/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.ept.facade;

import com.ept.entities.Commandeclient;
import com.ept.entities.Panier;
import java.util.Date;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.NoResultException;
import javax.persistence.NonUniqueResultException;
import javax.persistence.PersistenceContext;

/**
 *
 * @author Khalil
 */
@Stateless
public class CommandeclientFacade extends AbstractFacade<Commandeclient> {
    @PersistenceContext(unitName = "finalPU")
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }
    
     public List<Commandeclient> findByIdPanier(Panier panier) {
      
        // String historique = "historique" ;
       List<Commandeclient> list; 
        try {
            list = (List<Commandeclient>) getEntityManager().createNamedQuery("Commandeclient.findByIdPanier").setParameter("idPanier" , panier ).setParameter("validation", "valider").getResultList(); 
        } 
        
        catch (NoResultException exception) {
            return  null;
        }catch(NonUniqueResultException exception){
            return null;
        }
        return list;
    }
     
      public List<Commandeclient> findBydate(Date date) {
      
        // String historique = "historique" ;
       List<Commandeclient> list; 
        try {
            list = (List<Commandeclient>) getEntityManager().createNamedQuery("Commandeclient.findByDate").setParameter("date", date).getResultList(); 
        } 
        
        catch (NoResultException exception) {
            return  null;
        }catch(NonUniqueResultException exception){
            return null;
        }
        return list;
    }
     
     
     
     
     public List<Commandeclient> findHistorique(Panier panier) {
      
        // String historique = "historique" ;
       List<Commandeclient> list; 
        try {
            list = (List<Commandeclient>) getEntityManager().createNamedQuery("Commandeclient.findByIdPanier").setParameter("idPanier" , panier ).setParameter("validation", "historique").getResultList(); 
        }
        
      
        
        catch (NoResultException exception) {
            return  null;
        }catch(NonUniqueResultException exception){
            return null;
        }
        return list;
    }
     
     
     public List<Commandeclient> findAchat(Panier panier) {
      
        // String historique = "historique" ;
       List<Commandeclient> list; 
        try {
            list = (List<Commandeclient>) getEntityManager().createNamedQuery("Commandeclient.findByIdPanier").setParameter("idPanier" , panier ).setParameter("validation", "achat").getResultList(); 
        }
        
      
        
        catch (NoResultException exception) {
            return  null;
        }catch(NonUniqueResultException exception){
            return null;
        }
        return list;
    }

     public List<Commandeclient> findAchats(Panier panier) {
      
        // String historique = "historique" ;
       List<Commandeclient> list; 
        try {
            list = (List<Commandeclient>) getEntityManager().createNamedQuery("Commandeclient.findByIdPanier").setParameter("idPanier" , panier ).setParameter("validation", "achat").getResultList(); 
        } 
        
        catch (NoResultException exception) {
            return  null;
        }catch(NonUniqueResultException exception){
            return null;
        }
        return list;
    }

     
     
    public CommandeclientFacade() {
        super(Commandeclient.class);
    }
    
}
